"use strict"
//查询在线信息
const mvc = require("cosjs.mvc");
exports.online = async function () {
    const sid = this.get('sid', 'int');
    const uid = this.get('uid', 'string');
    const time = this.get('time', 'string');
    let tt;
    if (time) {
        tt = time.split(' - ');
    }






    let plog = mvc.model.mongo('plog', sid);
    let option = { "multi": true, "dataType": "array", "limit": 3000, 'batchSize': 3000 };
    // let exclude= ['_id', 'time', 'stime','uid','event','name','access'];
    let query = { 'event': 'pageEnter' };
    if (uid) {
        query['uid'] = uid;
    }
    if (tt) {
        let btime = Date.parse(tt[0]);
        let etime = Date.parse(tt[1]);
        query['$and'] = [{ 'stime': { '$gte': btime } }, { 'stime': { '$lt': etime } }];
    }


    let ret = await plog.find(query, option);
    let result = {}
    let uids = new Set();
    for (let i of ret) {
        uids.add(i._id);
        for (let k in i) {
            if (k == '_id') {
                continue;
            }
            if (k == 'time') {
                continue;
            }
            if (k == 'stime') {
                continue;
            }
            if (k == 'uid') {
                continue;
            }
            if (k == 'event') {
                continue;
            }
            if (k == 'name') {
                continue;
            }
            if (k == 'access') {
                continue;
            }
            if (k == 'lv') {
                continue;
            }
            if (!result[k]) {
                result[k] = 0;
            }
            result[k] += i[k];
        }
    }
    result.playerNum = uids.size;
    return result;
}